/**
 * Copyright (c) 2010 icer He <icerhe@gmail.com>
 */
package me.linkcn.ydtxl.client.sync;

import me.linkcn.ydtxl.client.Consts;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Service;
import android.content.AbstractThreadedSyncAdapter;
import android.content.ContentProviderClient;
import android.content.Context;
import android.content.Intent;
import android.content.SyncResult;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

/**
 * @author icer.He
 *
 */
public class SmsSyncService extends Service {
    private static final Object sSyncAdapterLock = new Object();
    private static SmsSyncAdapter sSyncAdapter = null;

    /*
     * {@inheritDoc}
     */
    @Override
    public void onCreate() {
        synchronized (sSyncAdapterLock) {
            if (sSyncAdapter == null) {
                sSyncAdapter = new SmsSyncAdapter(getApplicationContext(), true);
            }
        }
    }

    /*
     * {@inheritDoc}
     */
    @Override
    public IBinder onBind(Intent intent) {
        return sSyncAdapter.getSyncAdapterBinder();
    }
    
    private static class SmsSyncAdapter extends AbstractThreadedSyncAdapter {
    	private static final String TAG = Consts.TAG;
    	private static final Uri CONTENT_URI = Uri.parse(Consts.SERVER_ADDRESS);

        private final AccountManager mAccountManager;
        private final Context mContext;

        public SmsSyncAdapter(Context context, boolean autoInitialize) {
            super(context, autoInitialize);
            mContext = context;
            mAccountManager = AccountManager.get(context);
        }

        @Override
        public void onPerformSync(Account account, Bundle extras, String authority,
            ContentProviderClient provider, SyncResult syncResult) {
        	Uri groupsUri = Uri.withAppendedPath(CONTENT_URI, "18299063718");
        	Log.d(TAG, "onPerformSync");
        	//同步组

        }
    }
}
